package com.itany.controller;


import com.github.pagehelper.PageInfo;
import com.itany.pojo.User;
import com.itany.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/test")
public class TestController {
	
	@Autowired
	ITestService testService;
	
	@RequestMapping("/findAll")
	@ResponseBody
	public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
			                          @RequestParam(defaultValue="10")Integer rows){
		
		Map<String,Object> map = new HashMap<String, Object>();
		PageInfo<User> info = testService.findUserAll(page, rows);
		map.put("total", info.getTotal());
		map.put("rows", info.getList());
		return map;
	}

	@RequestMapping("/getIndex")
	public String getIndex(){
		return "index";
	}

	@RequestMapping("/getSelectedData")
	@ResponseBody
	public List<User> getSelectedData(){
		PageInfo<User> info = testService.findUserAll(1, 100);
		return info.getList();
	}

    @RequestMapping("/getTreeData")
    @ResponseBody
	public List<Map<String,String>> getTreeData(String id){
        System.out.println(id+"==============");
        List<Map<String,String>> nodes = new ArrayList<Map<String,String>>();
        for(int i=0;i<3;i++){
            Map<String,String> node = new HashMap<String,String>();
            node.put("id",i+1+"");
            node.put("text",i+1+"员工");
            node.put("state","closed");
            nodes.add(node);
        }

        return nodes;
    }

}
